from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SPUSpecification, SPU, SpecificationOption, SKUImage, SKU
from apps.meiduo_admin.serializers.images import SKUImageSerializer, SKUSerializer
from apps.meiduo_admin.serializers.options import OptionsSerializers
from apps.meiduo_admin.serializers.specs import SpecsSerializers, SPUserializers
from apps.meiduo_admin.utils import PageNum


class SKUImageView(ModelViewSet):
    # 指定序列化器
    serializer_class = SKUImageSerializer
    # 指定查询集
    queryset = SKUImage.objects.all()

    # 指定分页器
    pagination_class = PageNum

    # 获取关联的SKU信息数据
    def simple(self,request):
        # 1.查询SKU表
        data = SKU.objects.all()
        # 2.返回sku数据
        ser = SKUSerializer(data,many=True)

        return Response(ser.data)